package com.ogilvy.cms.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.ogilvy.cms.bean.CmsLog;
import com.ogilvy.cms.dao.CmsLogDao;
import com.ogilvy.frame.hibernate.BaseDaoImpl;
import com.ogilvy.frame.util.SqlReplace;

@Repository
public class CmsLogDaoImpl extends BaseDaoImpl<CmsLog> implements CmsLogDao{
	public List<CmsLog> getListByScreen(Map<String,String> screenMap) {
		StringBuffer hql = new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsLog cmslog where ");
		if(!"".equals(screenMap.get("startTime")))
		hql.append("CONVERT(varchar(100), cmslog.cmlTime, 23)>=convert(date,'"+screenMap.get("startTime")+"')");
		if(!"".equals(screenMap.get("endTime")))
		hql.append(" and  CONVERT(varchar(100), cmslog.cmlTime, 23)<=convert(date,'"+screenMap.get("endTime")+"')");
		// 建立查询语句
//		Query query = getSession().createQuery(hql.toString());
		Query query = getSession().createQuery(SqlReplace.replace(hql.toString()));
		
		List<CmsLog>  list = query.list();
		if (list == null) {
			list = new ArrayList<CmsLog>();
		}
		return list;
	}
}
